package weaver.formmode.customjavacode.modeexpand.kobelco;


import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.formmode.customjavacode.modeexpand.kobelco.utils.KobelcoUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;


/**
 * @Description: 客户分配的新建保存
 * @Param:
 * @return:
 * @Author: Dusongsong
 * @Date: 2021/3/23
 */
public class WeaKhfpNewSaveAction extends AbstractModeExpandJavaCodeNew {

    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<String, String>();
        try {
            User user = (User) param.get( "user" );
            int userid = user.getUID();
            int billid = -1;//数据id
            int modeid = -1;//模块id
            RequestInfo requestInfo = (RequestInfo) param.get( "RequestInfo" );
            if (requestInfo != null) {
                billid = Util.getIntValue( requestInfo.getRequestid() );
                modeid = Util.getIntValue( requestInfo.getWorkflowid() );
                if (billid > 0 && modeid > 0) {
                    /*
                     *@Description:
                     */
                    RecordSet rs = new RecordSet();
                    String tableName = KobelcoUtil.getModelTable(modeid);
                    String khk_tableName = "uf_khk";//客户库表
                    rs.writeLog( "WeaGcjhdtjbNewSaveAction-----------------" + billid );
                    //插入主表
                    rs.executeQuery( "select kh,khjl from "+tableName+" where id=?", billid );
                    if (rs.next()) {
                        String khjl = Util.null2String( rs.getString( "khjl" ) );//客户经理
                        String kh = Util.null2String( rs.getString( "kh" ) );//客户
                        rs.executeUpdate( "update " + khk_tableName + " set xsy="+khjl+" where id in ("+kh+")");
                        KobelcoUtil.getNewModeRight(userid,modeid,billid);
                    }
                }
            }
        } catch (Exception e) {
            result.put( "errmsg", "自定义出错信息" );
            result.put( "flag", "false" );
        }
        return result;
    }
}